#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <aclconio.h>
#include <define.h>
#include <transact.h>
#include <tran.h>
#include <gds.h>
#include <sizes.h>
#include "ConfProto.h"
#include "tblutil.h"
#include <\SOFTPAY\Ver30\source\include\sizes.h>
#include <\SOFTPAY\Ver30\HostSrc\citisrc\citiids.h>
#include <\SOFTPAY\Ver30\HostSrc\cpacsrc\cpacids.h>
#include <confio.h>

#include <\SOFTPAY\Ver30\source\include\PIT.h>



static void *storeFromStruct;

static int recordNum;
void registerPIT(void *ptr)
{
	 storeFromStruct = ptr;
}

void *dealWithAddressBoundary(void*address);
int	inLoadPITRecFromStruct (int inRecNumber, void *vdStruct)
{
	int inRet;
	char* tmp = (char*)vdStruct;

	registerPIT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inLoadConfRec(PIT_FILENAME, SIZE_PIT_REC, inRecNumber, vdStruct);

	recordNum = inRecNumber;
	return inRet;
}

void vdRestorePITRecFromStruct(void *vdStruct)
{
	registerPIT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	memcpy((char *) pvdGetPITRec(), vdStruct, SIZE_PIT_REC);

}

void vdCopyPITRecFromStruct(void *vdStruct)
{
	registerPIT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
		memcpy(vdStruct, (char *) pvdGetPITRec(), SIZE_PIT_REC);

}

int	inSavePITRecFromStruct (int inRecNumber,  void *vdStruct)
{
	int inRet;

	registerPIT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(PIT_FILENAME, SIZE_PIT_REC, inRecNumber, (char *) vdStruct);

	return inRet;
}

int	inUpdatePITRecFromStruct (void *vdStruct)
{
	int inRet;

	registerPIT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(PIT_FILENAME, SIZE_PIT_REC, recordNum, (char *) vdStruct);

	return inRet;
}

char* szGetTransTitleFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetTransTitle();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((PIT_REC*)vdStruct)->szTransTitle;
}

void vdSetTransTitleFromStruct(const char* szTransTitle, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetTransTitle(szTransTitle);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((PIT_REC*)vdStruct)->szTransTitle, szTransTitle, sizeof(((PIT_REC*)NULL)->szTransTitle)-1);
}

short inGetPwdLevelFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return inGetPwdLevel();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((PIT_REC*)vdStruct)->inPwdLevel;
}

void vdSetPwdLevelFromStruct(short inPwdLevel, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetPwdLevel(inPwdLevel);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((PIT_REC*)vdStruct)->inPwdLevel = inPwdLevel;
}

